package projetolp2.GraphicInterface;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import projetolp2.Sistem.Sistema;


public class VisualizarOpinioes extends MealPoints implements ActionListener{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JPanel panelMenu = new JPanel(new BorderLayout());
	private JPanel panel1 = new JPanel(new GridLayout(0, 1));
	private JPanel panel2= new JPanel(new GridLayout(0, 1));
	private JPanel panel3= new JPanel(new GridLayout(0, 1));
	private JPanel panel4= new JPanel(new GridLayout(0, 1));
	private JComboBox USUARIOS = new JComboBox();
	private JButton VOLTAR = new JButton(NomeBotoes.values()[idioma(IDIOMAPROGRAMA )].getVoltar());
	private JButton CONSULTAR = new JButton(NomeBotoes.values()[idioma(IDIOMAPROGRAMA )].getConsultar());
	final JLabel label = new JLabel("Escolha o usu�rio que deseja ver as opini�es");
	private JPanel panelFinal = new JPanel();
	
	public VisualizarOpinioes(){
		
	}private void ajudaDeBotoes(){
		VOLTAR.setToolTipText("Voltar a janela anterior");
		CONSULTAR.setToolTipText("Le mostra uma lista de estabelecimentos para voce verificar a opiniao do usuario escolhido acima");
		USUARIOS.setToolTipText("Selecione o usu�rio desejado");
	}
	
	public void actionPerformed(ActionEvent e){
		if(e.getSource() == VOLTAR){
			removerAdicionar(visualizarOpinioes,menu );
		}
		else if(e.getSource() == CONSULTAR){
			((OpinioesConsultaUsuario) consultaUsuario).usuarioAConsultar(USUARIOS.getSelectedItem().toString());
			removerAdicionar(visualizarOpinioes,((OpinioesConsultaUsuario) consultaUsuario).panel() );
		}
		
	}
	private void createComponents() {
		ajudaDeBotoes();
		
		VOLTAR.setMnemonic(KeyEvent.VK_I);
        VOLTAR.addActionListener(this);
        label.setLabelFor(VOLTAR);
        
        CONSULTAR.setMnemonic(KeyEvent.VK_I);
        CONSULTAR.addActionListener(this);
        label.setLabelFor(CONSULTAR);
        try {
			List<String> listaUsuarios = SISTEMA.nomeDeUsuarios();
			for (int i = 0; i < listaUsuarios.size();i++){
	        	USUARIOS.addItem(listaUsuarios.get(i));
	        }
		} catch (Exception e) {
			e.printStackTrace();
		}
        
        panel2.add(USUARIOS);
        panel3.add(CONSULTAR);
        panel4.add(VOLTAR);
        panel1.setBorder(BorderFactory.createEmptyBorder(
                10, //top
                10, //left
                10, //bottom
                10) //right
                );
        panel2.setBorder(BorderFactory.createEmptyBorder(
                10, //top
                10, //left
                10, //bottom
                10) //right
                );
        panel3.setBorder(BorderFactory.createEmptyBorder(
                10, //top
                10, //left
                10, //bottom
                10) //right
                );
        panel4.setBorder(BorderFactory.createEmptyBorder(
        		10, //top
                10, //left
                10, //bottom
                10) //right
                );
        
        panelFinal.add(panel2);
        panelFinal.add(panel3);
        panelFinal.add(panel4);
        panelMenu.add(panelFinal,BorderLayout.NORTH);
    }
	public Component panel(){
		createComponents();
		panelMenu.setVisible(true);
		
		
		return panelMenu;
	}
	public JComboBox getUsuarios(){
		return USUARIOS;
	}
}
